#include "stdafx.h"
#include "TermManager.h"

#include <fstream>

TermManager::TermManager(std::string& filename)
{
	m_Data = new TermData[230000];
	m_Data[0].index = 0;

	std::ifstream file(filename);
	while(file.good())
	{
		unsigned int index;
		file >> index;
		m_Data[index].index = index;
		file >> m_Data[index].name >> m_Data[index].df >> m_Data[index].cf >> m_Data[index].begin;

		m_Dictionary.insert(TermMap::value_type(m_Data[index].name, index));
	}
	file.close();
}

TermManager::~TermManager()
{
	delete[] m_Data;
}

TermData& TermManager::FindTermData(std::string& name)
{
	TermMap::iterator it = m_Dictionary.find(name);
	if(it == m_Dictionary.end())
		return m_Data[0];

	return m_Data[it->second];
}